<?php

namespace api\modules\v1\controllers;

use api\modules\v1\models\Article;
use api\modules\v1\models\Home;
use api\modules\v1\models\images\Images;
use cms\modules\v1\models\Upload;
use common\models\Functions;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;


/**
 * 首页控制器
 * Class HomeController
 * @package api\modules\v1\controllers
 */
class HomeController extends DefaultController
{

    public $modelClass = 'api\modules\v1\models\Home';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),
                'header' => 'access-token',
                'optional' => [
                    "home", 'upload', "about", "notice","about","service"
                ]
            ]
        ]);
    }

    public function actionUpload($imageUrl = '') {
        if (\Yii::$app->request->isPost) {
            return (new Upload())->uploadToAli();
        }
        if (\Yii::$app->request->isDelete) {
            return (new Upload())->deleteImage($imageUrl);
        }
    }

    public function actionSms() {
        $ip = Functions::getRemoteIp();
    }

    //获取客服信息
    public function actionService() {
        if (\Yii::$app->request->isGet) {
            return (new Home())->getServer();
        }
    }

    //获取客服信息
    public function actionConfig() {
        if (\Yii::$app->request->isGet) {
            return (new Home())->getConfig();
        }
    }

    //获取爱好信息
    public function actionConfigInterests() {
        if (\Yii::$app->request->isGet) {
            return (new Home())->getConfigInterests();
        }
    }
}
